Mechanism for using common code to handle hardware interrupts in multiple processor modes

ABSTRACT

An interrupt handler may be run in multiple processor modes on a data processing system having a processor for executing instructions and a memory for storing information. The sharing of interrupt handler code across multiple processor modes minimizes the switching between processor modes during the handling of interrupts. The mode in which the interrupt handler executes is dictated by the current processor mode. The indicator of the current processor mode directs the interrupt handler to use information that is appropriate for the current processor mode.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation of U.S. patent application Ser. No.08/436,085, filed May 8, 1995 U.S. Pat. No. 5,596,755, which is a FileWrapper Continuation of application Ser. No. 07/971,069 filed Nov. 3,1992, which is now abandoned.

TECHNICAL FIELD

The present invention relates generally to data processing systems and,more particularly, to using common code to handle hardware interrupts inmultiple processor modes.

BACKGROUND OF THE INVENTION

Many modern microprocessors are part of an evolving product line ofmicroprocessors provided by their respective manufacturers. The 80386microprocessor, sold by Intel Corporation of Cupertino, Calif., is anexample of such a microprocessor. The 80386 microprocessor evolved fromthe 80286 microprocessor, which, in turn, evolved from the 8086microprocessor. The later developed microprocessors of thismicroprocessor family have been designed to be compatible with theirearlier developed counterparts. Hence, the 80386 microprocessor can runprograms that are written for the 8086 microprocessor or the 80286microprocessor (i.e., the family exhibits upward compatibility).

The 8086 microprocessor is designed to run in a single mode ofoperation, known as "real mode". FIG. 1 depicts the addressing schemethat is employed by the 8086 microprocessor in real mode. In thisaddressing scheme, a 16-bit real address 10 is used to specify an entry20 in the physical memory 16. The real address 10 contains a 12-bitsegment base address 12 and a 4-bit offset 14. The physical memory 16 isdivided into segments containing contiguous blocks of memory. Thesegment base address 12 specifies the beginning of a segment 18. Theoffset 14 specifies an offset relative to the segment base address.

As is apparent from the above discussion, the 8086 microprocessoremploys a addressing scheme wherein there is no virtualization of theaddress space. The 80286 microprocessor built upon the addressing schemeof the 8086 microprocessor by adding virtualization. The 80286 may runin either real mode or protected mode (referred to hereinafter as '286protected mode). FIG. 2 provides a block diagram of the addressingscheme of '286protected mode. A 32-bit virtual address 22 is used in'286 protected mode. Bits 16-31 of the virtual address 22 hold a segmentselector 24. Bits 0-15 of the virtual address 22 hold a 16-bit offset26.

The segment selector 24 is used as an index to retrieve an entry 30 inthe segment descriptor table 28. The segment descriptor table 28 is anaddress translation mechanism for mapping a base address of a segment inthe virtual address space into a base address of a segment in thephysical address space. The entry 30 points to the base address of asegment 32. The offset 26 of the virtual address 22 points to a memorylocation 34 in the physical memory 16. The address of memory location 34is calculated by using the offset 26 to locate the address relative tothe base address held in entry 30 of the segment descriptor table 28.

The 80386 microprocessor has a real mode of operation analogous to thatemployed in the 8086 microprocessor. In this mode of operation, the80386 microprocessor can run programs written for the 8086microprocessor. The 80386 also has a '386 protected mode that is roughlyanalogous to the '286 protected mode of the 80286 microprocessor. The'386 protected mode, however, differs from the '286 protected mode inthat it employs paging and employs a 48-bit virtual address rather thana 32-bit virtual address.

FIG. 3 provides a block diagram of the addressing scheme employed in'386 protected mode. In '386 protected mode, the 80386 microprocessoremploys a 48-bit virtual address 36. Bits 0-31 of the virtual address 36hold an offset value 40, and bits 32-47 hold a selector, that is used asan index for an entry 44 in a segment descriptor table 42. Entry 44holds the base address for a segment. The base address held in entry 44is added to the 32-bit offset 40 by a summer 46 to yield a linearaddress 50.

Linear address 50 is then passed to a paging mechanism 52. Pagingmechanism 52 includes page directories and tables that are used totranslate the linear address 50 into a 32-bit physical address 54. Thephysical address 54 then is used to specify a entry 56 within physicalmemory 16.

The 80386 and 80286 microprocessors differ from the 8086 microprocessorin that they employ a number of privilege levels. The privilege levelsrange from level 0 to level 3, as shown in FIG. 4a. The privilege levelsare sometimes referred to as rings (e.g., ring 0, ring 1, ring 2 andring 3). Ring 0 is the greatest privilege level, and ring 3 is thelowest privilege level. Each memory segment in the address space of the80386 microprocessor has a ring associated with it. In order for a codesegment that is executing to gain access to a memory segment, the ringof the code segment must be equal or greater than the ring of the memorysegment being accessed. For example, a code segment having a ring of 0has access to memory segments at rings 0, 1, 2 or 3. In contrast, a codesegment at ring 3 may only access a memory segment at ring 3.

The privilege levels are provided to enhance security within the system.In particular, memory segments that require a high level of security areplaced in ring 0, and memory segments requiring a lower level ofsecurity are placed in ring 3. Typically, the operating system kernel isplaced in ring 0, and applications are run at ring 3 to preventapplications from altering the contents of the operating system kernel.

The 80386 microprocessor provides an additional mode of operation thatis known as the virtual 8086 mode (V86). In V86 mode, a protected modeoperating system may run real mode code in a virtualized manner. Theoperating system may provide a separate virtual machine for differentreal mode programs running on the microprocessor. Each virtual machineis an environment that is created through a combination ofmicroprocessor capabilities and operating system software. Only one ofthe virtual machines is actively running on the microprocessor at anypoint in time. The operating system may context switch between thevirtual machines to change the currently active virtual machine. FIG. 4bprovides an example of the use of the privilege levels in V86 mode. Thekernel of the operating system is run at privilege ring 0. Virtualmachines VM1, VM2 and VM3, in contrast, are run at ring 3. In theexample of FIG. 4b, the WINDOWS operating system and WINDOWS-basedapplications are being run on VM1. DOS is being run on VM2, and DOSapplications are being run on VM3.

The WINDOWS, version 3.0, operating system, by Microsoft Corporation, isconfigured to run on either an 80286 microprocessor or an 80386microprocessor. The WINDOWS, version 3.0, operating system runs in"standard mode" when implemented on a 80286 microprocessor or an 80386microprocessor with less than two megabytes of memory (see FIG. 5). Instandard mode, the microprocessor runs in real mode or '286 protectedmode. WINDOWS, version 3.0, runs in "enhanced mode" when it is run on a80386 microprocessor having at least two megabytes of memory. When theWINDOWS, version 3.0, operating system is run in enhanced mode, the80386 microprocessor runs in protected '386 mode or V86 mode (see FIG.5).

Handling of hardware interrupts while the microprocessor is running in'286 protected mode may be cumbersome because of the required switchingbetween modes. The steps performed in handling an interrupt in such aninstance are depicted in FIG. 6. Initially, a hardware interrupt isreceived in '286 protected mode (step 60). In order to handle theinterrupt, the microprocessor switches to real mode (step 62). When theinterrupt is generated, a pointer to the entry point of an interrupthandler routine is created. The pointer is a physical address like theaddress 10 shown in FIG. 1. The interrupt handler routine is thenexecuted to handle the interrupt (step 64 in FIG. 6), and when theinterrupt handler routine has completed, the microprocessor switchesback to '286 protected mode (step 66). The switching from '286 protectedmode to real mode and then from real mode to '286 protected mode incursa large amount of overhead.

The handling of interrupts in enhanced mode may also be cumbersome. Inenhanced mode, all hardware interrupts automatically switch theinterrupted microprocessor into ring 0. The system then must switch backto ring 3,because hardware interrupts are handled by interrupt handlerroutines that execute at ring 3. The resulting switching back and forthbetween rings is time consuming and burdensome.

The handling of a hardware interrupt in enhanced mode of WINDOWS,version 3.0, will now be described in more detail with reference toFIGS. 7a and 7b. Initially, a hardware interrupt is received by amicroprocessor (step 114 in FIG. 7b). The hardware interrupt has aninterrupt vector number (see FIG. 7a) that is used as an index into aninterrupt descriptor table (IDT) 91. The microprocessor uses theinterrupt vector number as an index in retrieving an entry 93 in the IDT91. The IDT entry 93 typically includes a selector 79 that points to aglobal descriptor table (GDT) entry 92. The IDT entry 98 also includesan offset 77. The GDT entry 92 has a pointer to kernel code 70, whichresides in physical memory 95. To avoid confusion, the role of pagingmechanism is omitted from this discussion. The microprocessor thenexecutes the kernel code 70.

The kernel code 70 is stored in a memory segment at ring 0. Data 72 forthe kernel is also stored at ring 0. (Note pointer 94 in GDT 97 thatpoints to data 72.) The transfer to the kernel code 70 involves a switchto ring 0 (step 116 in FIG. 7b). The kernel code 70 (FIG. 7a) determineswhich virtual machine should process the interrupt (step 118 in FIG.7b). If the virtual machine that is to handle the interrupt is not thecurrently active virtual machine, a context switch is performed (step120). The kernel code 70 (FIG. 7a) then transfers control to theappropriate interrupt handler in virtual machine VM0, VM1 or VM2. If theinterrupt is directed to VM0, the kernel code 70 transfers control tothe interrupt handler 78. In particular, the kernel code 70 provides anaddress for an entry point in the interrupt handler 78. The entry pointaddress includes a selector that points to entry 100 in LDT1. Entry 100includes a pointer to the page frame holding the interrupt handler code78 that is resident in physical memory 95. An offset is included in theentry point address, and the offset is used with the pointer to specifythe entry point in the interrupt handler. LDT1 also includes an entry 96that points to code for VM0 and an entry 98 that points to data 76 forVM0.

If, however, the interrupt should be handled by VM1, the kernel code 70passes control to interrupt handler 84. The kernel code specifies avirtual address that includes a selector pointing to entry 104 in LDT2.Entry 104 at LDT2 holds a pointer to interrupt handler code 84. Theoffset of the virtual address is used with the pointer to specify theentry point. LDT2 also includes an entry 102 that points to code 80 forVM1 and an entry 107 that points to data 82 for VM1.

If the interrupt is to be handled by VM2, the kernel code 70 passescontrol to interrupt handler 90 at a linear address which is translatedto a physical address using LDT3. Specifically, the kernel codesspecifies a virtual address that includes a selector pointing to entry112 in LDT3. Entry 112 in LDT3 includes a pointer to the page frameholding the interrupt handler code 90. The offset of the virtual addressis used with the pointer to specify the entry point in the interrupthandler routine. LDT3 also includes an entry 108 that points to code 86for VM2 and an entry 110 that points to data 88 for VM2.

All of the interrupt handlers 78, 84 and 90 are stored in memorysegments at ring 3. Thus, when control is transferred to the interrupthandler, a switch must be made to ring 3 (step 122 in FIG. 7b). Once theinterrupt has been handled, the system signals the end of the interrupt(step 126). Generally, the end of an interrupt is signalled by writinginto a hardware register.

Another proposed solution has been to determine what mode themicroprocessor is in when it receives an interrupt and then invoking aunique interrupt handler routine based upon the determination of themode. Separate code is provided for interrupt handlers of each mode.Unfortunately, there is a great deal of overhead in providing theprocedures to determine the current mode of the system and providingseparate interrupt handlers for each mode.

SUMMARY OF THE INVENTION

In accordance with a first aspect of the present invention, a method isexecuted in a data processing system having a processor for executinginstructions in storage for storing information. In accordance with thismethod of the first aspect of the present invention, code is providedfor an interrupt handler that may be run in multiple processor modes. Adetermination is made regarding the current processor mode for theprocessor. This method may further comprise the additional step ofstoring the current processor mode in storage so that the currentprocessor mode is determined by examining the stored current processormode. The current processor mode may be one in which the instructionsthat are executed by the processor use virtual addresses. Conversely,the current processor mode may be one in which the instructions that areexecuted by the processor use physical addresses. Still further, theinterrupt handler may be stored in a portion of the storage that isaccessible by the processor in either of the processor modes.

In accordance with another aspect of the present invention, a method ofhandling interrupts is executed in a data processing system having aprocessor for executing instructions and a storage for storinginformation. In accordance with the method of this aspect of the presentinvention, an indicator of a current processor mode is stored instorage. Also stored in storage is information to be used by theinterrupt handler when run in the first processor mode and informationto be used by the interrupt handler when run in a second processor mode.It is then determined what the current processor mode is. If the currentprocessor mode is the first mode, the interrupt handler is run using thestored information for the first processor mode. On the other hand, ifthe current processor mode is the second processor mode, the interrupthandler is run using the stored information for the second processormode.

In accordance with the second aspect of the present invention, the firstprocessor mode may be one in which the instructions that are executed bythe processor use virtual addresses. The second processor mode maycomprise a processor mode in which the instructions that are executed bythe processor use physical addresses. When the first processor mode issuch that the instructions executed by the processor use virtualaddresses, the information to be used by the interrupt handler may bevalues that specify segments of memory in a virtual memory addressspace, such as an index to an entry in a segment descriptor table.

The first processor mode may also be a processor mode in which theinstructions that are executed by the processor use physical addresses.In this case, the information to be used by the interrupt handler in thefirst processor mode includes values that specify memory blocks in aphysical address space. The information to be used by the interrupthandler when run in the first processor mode may be offset by a fixedoffset from the information to be used by the interrupt handler when runin the second processor mode. The fixed offset may be specified by theindicator of the current processor mode. In fact, the indicator of thecurrent processor mode may be equal to the fixed offset.

The storage preferably comprises a memory that is logically partitionedinto segments of contiguous blocks of memory. When such memory isemployed, the first processor mode may be a first privilege level, andthe second processor mode may be a second privilege level. The privilegelevels are associated with each segment of memory such that in order forthe processor to gain access to a segment of the memory, the processormust be executing in a processor mode having a privilege level equal toor greater than the privilege level of the memory segment.

The method of the second aspect of the present invention may comprisethe additional steps of providing a control procedure for the firstprocessor mode and providing a control procedure for the secondprocessor mode. The control procedure for the first processor mode iscalled when the current processor mode is the first processor mode.Similarly, the control procedure of the second processor mode is calledwhen the current processor mode is the second processor mode.

In accordance with yet another aspect of the present invention, the dataprocessing system includes a memory for holding data and code. Thememory holds an interrupt handler routine that is executable in multipleprocessor modes. The memory also holds an indicator of a currentprocessor mode, the information to be used by the interrupt handler whenrun in a first processor mode, and the information to be used by theinterrupt handler when run in a second processor mode. The dataprocessing system further includes a processor for executing theinterrupt handler in the first processor mode when the current processormode is the first processor mode and for executing the interrupt handleron the second processor mode when the current processor mode is thesecond processor mode. The memory may further hold a segment descriptortable for translating virtual addresses into physical addresses. Inaddition, the indicator of the current processor mode may specify anoffset that is used by the processor to retrieve the information to beused by the interrupt handler in the current processor mode.

BRIEF DESCRIPTION OF THE DRAWINGS

A preferred embodiment of the present invention will be described belowrelative to the drawings.

FIG. 1 depicts the addressing scheme used in real mode in the 8086microprocessor.

FIG. 2 depicts the addressing scheme used in '286 protected mode on the80286 microprocessor.

FIG. 3 depicts the addressing scheme used in '386 protected mode on the80386 microprocessor.

FIG. 4a depicts the privilege level scheme employed in the 80386microprocessor.

FIG. 4b depicts how the privilege levels of FIG. 4a are employed in theVM mode of the 80386 microprocessor.

FIG. 5 is a diagram illustrating the relationship between processormodes and the modes of the WINDOWS, version 3.0, operating system.

FIG. 6 is a flowchart illustrating the steps involved in handlinginterrupts in standard mode.

FIG. 7a is a diagram illustrating the handling of an interrupt inenhanced mode.

FIG. 7b is a flowchart of the steps involved in handling an interrupt inenhanced mode.

FIG. 8 is a block diagram of an illustrative data processing system forpracticing the present invention.

FIG. 9a is a block diagram illustrating how a preferred embodiment ofthe present invention handles an interrupt in standard mode.

FIG. 9b is a more detailed block diagram of the data block 168 of FIG.9a.

FIG. 9c is a flowchart illustrating the steps performed by the interrupthandler routine of a preferred embodiment of the present invention instandard mode.

FIG. 10a is a block diagram that illustrates how interrupts are handledby a preferred embodiment of the present invention in enhanced mode.

FIG. 10b is a more detailed block diagram of the data block 168 of FIG.10a.

FIG. 10c is a flowchart illustrating the steps performed by a preferredembodiment of the present invention in handling interrupts in enhancedmode.

FIG. 11 is a flowchart illustrating steps performed by theinitialization routine 196 of FIG. 10a.

DETAILED DESCRIPTION OF THE INVENTION

A preferred embodiment of the present invention provides a mechanism forsharing common code to handle interrupts across multiple processormodes. The term "processor modes" in the present context is meant toinclude modes such as real mode and protected mode, as well as privilegelevels such as ring 0 and ring 3. A preferred embodiment will bedescribed below relative to implementations on the 80286 microprocessorand the 80386 microprocessor. Moreover, the preferred embodiment will bedescribed relative to an implementation on the WINDOWS operating system.Those skilled in the art will appreciate that the invention is notlimited to use of an 80286 microprocessor, an 80386 microprocessor orthe WINDOWS operating system. The preferred embodiment is describedbelow relative to these entities merely for illustrative purposes.

FIG. 8 shows a block diagram of a data processing system 140 that issuitable for implementing the preferred embodiment described herein.This data processing system is merely illustrative and should not beviewed as restricting the present invention. Those skilled in the artwill know other suitable data processing system configurations forpracticing the present invention.

The data processing system 140 includes a central processor unit (CPU)142, a memory sub-system 146, having a memory 154 and an input/output(I/O) sub-system 144, having I/O devices 152. The CPU 142, the memorysub-system 146 and the I/O sub-system 144 are interconnected through abus 148. The CPU 142 includes registers 150, such as CS and ES segmentregisters, an instruction pointer (IP) register and a DI general purposeregister. The CPU 142 may be realized as an 80386 microprocessor or an80286 microprocessor. In the 80386 microprocessor, the DI generalpurpose register constitutes the lower 16 bits of an EDI general purposeregister. In the 80286 microprocessor, the DI register is a separateregister that is not part of a larger register.

The preferred embodiment described herein minimizes the overheadinvolved in handling interrupts in '286 protected mode by adopting anapproach like that depicted in FIG. 9a. The physical memory 164 holds aninterrupt handler routine 166, a data block 168 and an initializationroutine 170, which are all part of a communications driver. The physicalmemory also holds segments 172 and 174. The system of FIG. 9a furtherincludes an interrupt descriptor table (IDT) 160 and a segmentdescriptor table 180. In general, the approach of FIG. 9a is to store adata block 168 with an interrupt handler routine 166. A pointer to thisdata block is provided when the interrupt handler routine 166 isinvoked. The interrupt handler routine 166 uses the data in the datablock 168 to determine the mode in which the interrupt handler shouldoperate. The data block 168 includes pointers to information that isused by the interrupt handler routine in each of the respectiveprocessor modes.

The system of FIG. 9a operates as follows. Each hardware interrupt hasan interrupt vector number associated with it. This interrupt vectornumber is used as an index into the IDT 160 to entry 162. The IDT usesthe vector number of the interrupt to determine what interrupt handlerroutine it should invoke to handle the interrupt and to determine theproper entry point in the interrupt handler. The entry 162 that isindexed by the interrupt vector includes a code segment (CS) field thatpoints to the segment holding the interrupt handler routine 166. Entry162 also includes an instruction pointer (IP) field that points to theentry point within the interrupt handler routine 166. The CS field isloaded into the CS segment register of the CPU, and the IP field isloaded into the instruction pointer of the CPU 142 (FIG. 8).

The CPU 142 then begins executing the interrupt handler routine 166(FIG. 9a) at the entry point as specified by the CS and IP registers.The interrupt handler routine initially executes in real mode. Theinterrupt handler routine 166 is passed a data block pointer 163, whichpoints to the data block 168. The steps performed by the interrupthandler routine 166 are shown in the flowchart of FIG. 9c. Initially,the interrupt handler routine looks to entry 201 (FIG. 9b) in the datablock 168. Entry 201 holds a mode indicator (step 190 in FIG. 9c). Entry201 is at an address specified by the selector held in segment registerES and an offset held in the DI register. The proper values are loadedinto ES and DI during initialization of the system. Entry 201 holds avalue of either "0" or "4". A value of "0" specifies that the interrupthandler is to be performed in '286 protected mode, and a value of "4"indicates that the interrupt handler is to be executed in real mode.

Once the interrupt handler routine 166 (FIG. 9a) has examined thecontents of entry 201 (FIG. 9b), it knows the mode in which it is to beexecuted. Hence, the interrupt handler loads appropriate selectors orsegment base addresses to handle the interrupt (step 192 in FIG. 9c).The value in entry 201 (FIG. 9b) is used to directly obtain theselectors or segment base addresses (depending on the selected mode). Inparticular, each selector to be used by the interrupt handler in '286protected mode is separated from the corresponding segment to be used bythe interrupt handler in real mode by 4 bytes. Therefore, an offset of"0" causes the selector to be chosen, whereas an offset of "4" causesthe segment base address to be chosen. For example, when entry 201 (FIG.9b) holds a value of "0", the offset is "0", and the selector 203 atbyte 20 is used by the interrupt handler routine 166. A value of "0" isan indication that the interrupt handler is to be run in '286 protectedmode and, therefore, virtual addressing and selectors are used. On theother hand, if a value of "4" is stored in entry 201, the interrupthandler 166 routine is to be run in real mode and real addresses areused. The offset of "4" is used to obtain the segment base address 205at byte 24.

FIG. 9a shows how the selector 203 (FIG. 9b) or segment base address 205is used to access segment 172 or 174, respectively. Selector 203 (FIG.9b) points to entry 182 in the segment descriptor table 180. Entry 182points to a segment 172. The segment base address 205 (FIG. 9b) does notpoint to an entry in the segment descriptor table 180; rather, itdirectly specifies the address for segment 174. It should be appreciatedthat although only one such selector and segment base address pair areshown in FIG. 9b, the data block may include multiple pairs of suchselectors and segment base addresses.

Once the interrupt has been fully handled, the interrupt handler routineseeks to make it known that the interrupt is finished. To signal the endof an interrupt, the interrupt handler generally calls a controlprocedure (step 196 in FIG. 9c). The preferred embodiment describedherein provides the ability to call the control procedure in either realmode or '286 protected mode, depending upon the value stored in entry201 (FIG. 9b). The value in entry 201 is used as an offset to calleither a selector 207 or a selector 208 in a fashion analogous to thatdescribed above.

In FIG. 9b, it is illustratively shown that selector 207 is stored atbyte 40, which is the byte at offset "0". The offset "0" selector 207 iscalled when the control procedure is to be executed in '286 protectedmode. This selector 207 is then used to access entry 184 in segmentdescriptor table 180. Entry 184 includes a pointer to control procedure176. When the control procedure is to be executed in real mode, entry201 (FIG. 9b) holds a value of "4". The segment base address 208 at byte44 of data block 168 is used. As a result, a control procedure 178 isdirectly called using the segment base address 208.

In enhanced mode, the preferred embodiment described herein operates ina manner similar to the above-described approach for standard mode. Thedifferences between operation in enhanced mode and operation in standardmode will become more apparent from the discussion below. FIG. 10aillustrates how interrupts are handled in enhanced mode. A physicalmemory 164 holds the interrupt handler routine 166, a data block 168 andan initialization routine 196. In addition, the physical memory 164holds two pages of memory 198 and 200, as well as control procedures 202and 204. Control procedure 202 is designed to operate in ring 0, whilecontrol procedure 204 is designed to operate in ring 3. A GDT 208 andLDT 210 are provided to point to page frames within the physical memory164. An IDT 206 is provided to specify what interrupt handler routinesare to be used and to specify the entry points into such interrupthandler routines.

In enhanced mode, the hardware interrupt has an interrupt vector numberassociated with it. This interrupt vector number serves as an index intothe IDT 206. This IDT 206 differs somewhat from the IDT 160 used instandard mode. The indexed entry 214 in the IDT 206 includes an offset216 and a selector 218. The selector 218 in the IDT entry 214 is used topoint to an entry 220 in the GDT 208. The entry 220 in the GDT 208includes a field that specifies the privilege level of the interrupthandler routine that is pointed to by selector 222. In the illustrativecase of FIG. 10a, the selector points to the interrupt handler routine166, which is run at ring 0 initially. The entry point into theinterrupt handler routine 166 is specified by the offset 216 of theentry 214 in the IDT 206.

The interrupt handler routine 166 begins executing at the entry pointspecified by the offset 216. A flowchart of the steps performed by theinterrupt handler routine is provided in FIG. 10c. Initially, the ES andDI registers are used to specify the address of the entry in the datablock 168 which holds a ring indicator (step 250 in FIG. 10c). The ringindicator is held at entry 258 of the data block, as shown in the moredetailed depiction of the data block in FIG. 10b. Entry 258 holds avalue of "0" or "4". A value of "0" in entry 258 indicates that theinterrupt handler is to run at ring 3. On the other hand, a value of "4"indicates that the interrupt handler is to run at ring 0.

The ring indicator at entry 258 is used as an offset to obtain theappropriate selectors (step 252 in FIG. 10c). The selectors forinformation to be used by the interrupt handler routine 166 (FIG. 10a)when run at ring 0 are offset by 4 bytes from the selectors to be usedby the interrupt handler routine when run at ring 3. For instance, asshown in FIG. 10b, when the interrupt handler is to be run at ring 3, a"0" offset value in entry 258 directs the interrupt handler to theselector 260 at byte 20. Selector 260 points to entry 236 in the LDT210. Entry 236 includes a selector 238 that points a page frame ofmemory 200. Entry 236 contains bits indicating the privilege level ofpage frame 200. In this instance, the bits in entry 236 indicate thatpage frame 200 is stored at ring 3.

When the interrupt handler is to be run at ring 0, an offset of "4"directs the interrupt handler to selector 262 at an offset of 4 bytesrelative to the corresponding selector for ring 3. The selector 262points to an entry 228 in the GDT 208. Entry 228 includes a selector 232that points to page frame 198. Bits in entry 228 specify that page frame198 has a privilege level of 0. Hence, when the interrupt handler runsat ring 0, selector 262 (FIG. 10b) is used. In contrast, when theinterrupt handler runs at ring 3, selector 260 is used.

Once the interrupt handler 166 (FIG. 10b) knows the selectors 260 or 262it is to use, the interrupt handler finishes handling the interrupt(step 254 in FIG. 10c). The interrupt handler 166 (FIG. 10a) thendetermines which control procedure to call so as to signal the end ofthe interrupt (256). The calling of the control procedure is alsodictated by the offset.

With an offset of "0", the interrupt handler 166 (FIG. 10a) chooses aselector 264 to invoke the control procedure that executes at ring 3. InFIG. 10b, the selector 264 is held at byte 40 and points to entry 240 inLDT 210. Entry 240 (FIG. 10a) includes a pointer 242 to the page frameholding control procedure 204. Entry 240 also includes bits that specifythat the control procedure 204 executes at ring 3.

A selector 266 (FIG. 10b) for a control procedure 202 (FIG. 10a) thatruns at ring 0 is offset by 4 bytes from selector 264 (FIG. 106) for thecontrol procedure that runs at ring 3. Selector 266 is shown in FIG. 10bas being at byte 44. Selector 266 points to entry 230 (FIG. 10a) in GDT208. The entry 230 includes a pointer 234 that points to a page frameholding control procedure 202. The entry 230 also includes bitsspecifying that the control procedure 202 executes at ring 0.

The data contained within data block 168 (FIG. 10b) is stored therein atinitialization. To facilitate the storage of data in this data block168, the initialization routine 196 (FIG. 10a) is invoked during systemboot. FIG. 11 presents a brief flowchart of the steps performed by theinitialization routine in enhanced mode. The initialization routine isresponsible for storing the ring 3 selector 260 (FIG. 10b) in the datablock (step 270 in FIG. 11). The initialization routine then calls thekernel code to register the ring 0 interrupt handler (step 272). Thekernel registers the interrupt handler routine and then storesappropriate ring 0 selector 262 (FIG. 10b) in the data block 168.

While the present invention has been described with reference to apreferred embodiment thereof, those skilled in the art will know ofvarious changes in form that may be made without departing from thespirit and scope of the claim invention as defined in the appendedclaims.

We claim:
 1. In a data processing system having a processor forexecuting instructions and operating at different privilege levels, astorage for storing information and an interrupt handler for handling atype of interrupt, a method of handling interrupts comprising the stepsof:a) storing an indicator of a current privilege level of executinginstructions in the storage; b) storing information to be used by theinterrupt handler when run in a first privilege level in the storage andstoring information to be used by the interrupt handler when run in asecond privilege level in the storage; c) receiving an interrupt of thetype handled by the interrupt handler; d) in response to receiving theinterrupt, determining the current privilege level by examining theindicator in storage; e) running the interrupt handler using the storedinformation for the first privilege level in response to determiningthat the current privilege level is the first privilege level to avoidswitching privilege levels; and f) running the interrupt handler usingthe stored information for the second privilege level in response todetermining that the current privilege level is the second privilegelevel to avoid switching privilege levels.
 2. In a data processingsystem that has a processor that runs in processor modes of real mode orprotected mode and a storage for storing an interrupt handler forhandling interrupts, a method comprising the computer-implemented stepsof:running the processor in the protected mode; providing a data blockalong with the interrupt handler in the storage, said data blocksholding an offset value; receiving an interrupt while the processor isrunning in the protected mode; providing a data pointer to the datablock for use by the interrupt handler; with the interrupt handler,using the data pointer to locate the data block and examining the offsetvalue in the data block; and using data at an offset specified by theoffset value to run the interrupt handler in the protected mode withoutswitching to the real mode.
 3. In a data processing system having aprocessor that runs programs at different privilege levels and a storagefor storing an interrupt handler for handling interrupts, a methodcomprising the computer-implemented steps of:running a program on theprocessor at a first of the privilege levels; providing a data blockalong with the interrupt handler in the storage, said data block holdingan offset value; receiving an interrupt while the program is run on theprocessor at a first of the privilege levels; providing a data pointerto the data block for use by the interrupt handler; with the interrupthandler, using the data pointer to locate the data block and examiningthe offset value in the data block; and using data at an offsetspecified by the offset value to run the interrupt handler at the firstof the privilege levels.
 4. In a data processing system having aprocessor for executing instructions and operating in differentprocessor modes, a storage for storing information and an interrupthandler for handling a type of interrupt, a computer-readable storagemedium holding instructions for performing a method of handlinginterrupts comprising the steps of:a) storing an indicator of a currentprocessor mode in the storage; b) storing information to be used by theinterrupt handler when run in a first processor mode in the storage andstoring information to be used by the interrupt handler when run in asecond processor mode in the storage; c) receiving an interrupt of thetype handled by the interrupt handler responds; d) in response toreceiving the interrupt, determining what the current processor mode isby examining the indicator in storage; e) running the interrupt handlerusing the stored information for the first processor privilege level inresponse to determining that the current processor mode is the firstmode to avoid switching processor modes; and f) running the interrupthandler using the stored information for the second processor mode inresponse to determining that the current processor mode is the secondprocessor mode to avoid switching processor modes.
 5. Thecomputer-readable storage medium of claim 4 wherein the instructions forperforming the step of storing information to be used by the interrupthandler when run in the first processor mode store information to beused by the interrupt handler when run in the first processor mode inwhich the instructions that are executed by the processor use virtualaddresses.
 6. The computer-readable storage medium of claim 5 whereinthe instructions for performing the step of storing information to beused by the interrupt handler when run in the second processor modestore information to be used by the interrupt handler when run in thesecond processor mode in which the instructions that are executed by theprocessor use physical addresses.
 7. The computer-readable storagemedium of claim 5 wherein the instructions for performing the step ofstoring information to be used by the interrupt handler when run in thefirst processor mode store values that specify segments of memory in avirtual memory address space to be used by the interrupt handler whenrun in the first processor mode.
 8. The computer-readable storage mediumof claim 7 wherein the instructions for performing the step of storingvalues that specify segments of memory in a virtual address space storeat least one index to an entry in a segment descriptor table.
 9. Thecomputer-readable storage medium of claim 4 wherein the instructions forperforming the step of storing information to be used by the interrupthandler when run in the first processor mode store information in thestorage to be used by the interrupt handler when run in the firstprocessor mode in which the instructions that are executed by theprocessor use physical addresses.
 10. The computer-readable storagemedium of claim 9 wherein the instructions for performing the step ofstoring information to be used by the interrupt handler when run in thefirst processor mode in the storage store values that specify memoryblocks in a physical address space.
 11. The computer-readable storagemedium of claim 5 wherein the instructions for performing the step ofstoring information to be used by the interrupt handler when run in thefirst processor mode store the information to be used by the interrupthandler when run in the first processor mode at a location in thestorage that is offset by a fixed offset from a location that stores theinformation to be used by the interrupt handler when run in the secondprocessor mode that is stored in the storage.
 12. The computer-readablestorage medium of claim 11 wherein the instructions for performing thestep of storing the information to be used by the interrupt handler whenrun in the first processor mode store the information to be used by theinterrupt handler at a location in the storage that is offset by a fixedoffset specified by the indicator of the current processor mode.
 13. Thecomputer-readable storage medium of claim 12 wherein the instructionsfor performing the step of storing the indicator of the currentprocessor mode in the storage store the fixed offset between thelocation in the storage that stores the information to be used by theinterrupt handler when run in the first processor mode and the locationin the storage that stores the information to be used by interrupthandler when run in the second processor mode as the indicator of thecurrent processor mode.
 14. The computer-readable storage medium ofclaim 4 wherein the storage is a memory that is logically partitionedinto segments of contiguous blocks of memory and wherein the firstprocessor mode is a first privilege level, the second processor mode isa second privilege level, and privilege levels are associated with eachsegment of memory such that in order for the processor to gain access toa segment of memory, the processor must be executing in a processor modehaving a privilege level that is equal or greater than the privilegelevel of the memory segment and wherein the instructions for performingthe step of storing information store information to be used by theinterrupt handler when run in the first privilege level and storeinformation to be used by the interrupt handler when run in the secondprivilege level.
 15. The computer-readable storage medium of claim 4,further holding instructions for:storing a control procedure for thefirst processor mode in the storage; storing a control procedure for thesecond processor mode in the storage; calling the control procedure ofthe first processor mode when the current processor mode is the firstprocessor mode; and calling the control procedure of the secondprocessor mode when the current processor mode is the second processormode.
 16. In a data processing system having a processor for executinginstructions and operating at different privilege levels, a storage forstoring information and an interrupt handler for handling a type ofinterrupt, a computer-readable storage medium holding instructions forperforming a method of handling interrupts comprising the steps of:a)storing an indicator of a current privilege level of executinginstructions in the storage; b) storing information to be used by theinterrupt handler when run in a first privilege level in the storage andstoring information to be used by the interrupt handler when run in asecond privilege level in the storage; c) receiving an interrupt of thetype handled by the interrupt handler; d) in response to receiving theinterrupt, determining the current privilege level by examining theindicator in storage; e) running the interrupt handler using the storedinformation for the first privilege level in response to determiningthat the current privilege level is the first privilege level to avoidswitching privilege levels; and f) running the interrupt handier usingthe stored information for the second privilege level in response todetermining that the current privilege level is the second privilegelevel to avoid switching privilege levels.
 17. In a data processingsystem that has a processor that runs in processor modes of real mode orprotected mode and a storage for storing an interrupt handler forhandling interrupts, a computer-readable storage medium holdinginstructions for performing a method comprising the steps of:running theprocessor in the protected mode; providing a data block along with theinterrupt handler in the storage, said data blocks holding an offsetvalue; receiving an interrupt while the processor is running in theprotected mode; providing a data pointer to the data block for use bythe interrupt handler; with the interrupt handler, using the datapointer to locate the data block and examining the offset value in thedata block; and using data at an offset specified by the offset value torun the interrupt handler in the protected mode without switching to thereal mode.
 18. In a data processing system having a processor that runsprograms at different privilege levels and a storage for storing aninterrupt handler for handling interrupts, a computer-readable storagemedium holding instructions for performing a method comprising the stepsof:running a program on the processor at a first of the privilegelevels; providing a data block along with the interrupt handler in thestorage, said data block holding an offset value; receiving an interruptwhile the program is run on the processor at a first of the privilegelevels; providing a data pointer to the data block for use by theinterrupt handler; with the interrupt handler, using the data pointer tolocate the data block and examining the offset value in the data block;and using data at an offset specified by the offset value to run theinterrupt handler at the first of the privilege levels.